package org.mybatis.generator.codegen.mybatis3.javamapper.elements;

import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.codegen.mybatis3.ExtMyBatis3FormattingUtilities;

import java.util.Set;
import java.util.TreeSet;

/*********************************************************
 * 文件名称：SelectByExampleWithPageMethodGenerator.java
 * 系统名称：cxycloud
 * 模块名称：org.mybatis.generator.codegen.mybatis3.javamapper.elements
 * 功能说明：
 * 开发人员 @author：caoxy
 * 开发时间 @date：2023/8/24 15:46
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class SelectByExampleWithPageMethodGenerator extends AbstractJavaMapperMethodGenerator {
    public SelectByExampleWithPageMethodGenerator() {
    }

    public void addInterfaceElements(Interface interfaze) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet();
        FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
        importedTypes.add(type);
        importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
        importedTypes.add(new FullyQualifiedJavaType("com.github.pagehelper.Page"));
        importedTypes.add(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper"));
        importedTypes.add(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Param"));
        Method method = new Method(ExtMyBatis3FormattingUtilities.ATTR_SELECT_BY_EXAMPLE_WITH_PAGE_STATEMENT_ID);
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setAbstract(true);
        FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("Page<" + introspectedTable.getBaseRecordType() + ">");
        method.setReturnType(returnType);
        FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
        method.addParameter(new Parameter(exampleType, "example", "@Param(\"example\")"));
        importedTypes.add(exampleType);
        FullyQualifiedJavaType pageType = new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds");
        method.addParameter(new Parameter(pageType, "rowBounds", "@Param(\"rowBounds\")"));
        importedTypes.add(pageType);
        context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
        addMapperAnnotations(interfaze, method);
        if (context.getPlugins().clientSelectByExampleWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
            addExtraImports(interfaze);
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }

    }

    public void addMapperAnnotations(Interface interfaze, Method method) {
    }

    public void addExtraImports(Interface interfaze) {
    }
}
